a, b, c = 1, 2, 3
a, b = b, a

print(a, b, c, sep='--', end='  ')

list = ['python', 'mysql', 'linux', 'shell']
list.append('day')
list.extend('day')
list.insert(3, 'day03')  # 插入先说位置
print(list)

print(list.index('mysql'))

print(list.pop(0))  # 弹出第几个
print(list[0:2])
print(list)

str = '   mysql   linux  '
# 去除两边空格 strip()
str1 = str.strip()

print(str1)
def _20():
    print('__' * 20)
_20()

str = 'mysql,linux,python'
str1 = str.split(',')  # 以,分割
print(str1)
_20()

str2 = str.upper()  # 大写upper
print(str2)

str3 = str2.lower() # 小写lower
print(str3)

str4 = str.title()  # 首字母大写title
print(str4)

# 判断是以什么开头结尾 startswith('my')  endswith('l')

print(str.startswith('my'))

_20()

print(str.endswith('on'))

list1 = ['python', 'mysql', 'linux']
str1 = '-'.join(list1)  # 以——拼接
print(str1)

print(str1.title())

str2 = '.'.join(list1)

print(str2)

str1 = 'hello python, hello mary'

str2 = str1.replace('hello', '你好')  # 替换

print(str2)

_20()

str1 = '123'
str2 = 'sbc'
str3 = 'a123'

print(str1.isdigit())  # isdigit()
print(str2.isalpha())  # isalpha()
print(str3.isalnum())  # isalnum()

print(str2.index('b'))
print(str2.find('b'))

tuple1 = ('hello', 'good', 'mary', 'linux')
print(tuple1[:2])  # ()元组 tuple
print(tuple1[0:3:2])

for i in tuple1:
    print(i)
a, b, c, d = tuple1

print(a)  # 拆包
print(c)

dict1 = {'name': 'mary', 'age': 18, 'addr': 'chengdu'}
print(dict1)

print(dict1.pop('addr'))
print(dict1)
_20()
for i in dict1.items():
    print(type(i), end='')
    print(i)

set1 = {'a', 'b', 'c', 'a'}
print(set1)

print('java' in ['python', 'mysql'])

_20()

for i in range(1,10):
    for j in range(1,10):
        if j <= i:
            print(f'{j}*{i}={j*i}', end='\t')
    print()

str1 = 'mary'
str2 = 'mary'
print((str2 is not str1))

fn = lambda a, b: a + b
print(fn(3, 4))

with open('resource/demo01.txt', 'w', encoding='utf8') as f:
    f.write('hello mary\nhello lishi\nzhangsan')

with open('resource/demo01.txt', 'r', encoding='utf8') as f:
    for i in f.readlines():
        print(i)

import os

print(os.path.abspath('文件操作.py'))

# 文件重命名
os.rename('resource/demo01.txt', 'resource/demo02.txt')
os.remove('resource/demo02.txt')
with open('resource/demo.txt', 'w', encoding='utf8') as f:
    f.write('mary')
os.remove('resource/demo.txt')  # 删除文件

if os.path.isdir('resource/01'):
    print('有这个路径')
else:
    os.mkdir('resource/01')  # 创建文件夹 相对路径
    os.mkdir('resource/02')
os.rmdir('resource/01')
import shutil
shutil.rmtree('resource/02')

print(os.getcwd())  # 当前脚本路径

# os.chdir('../..')
print(os.getcwd())

print(os.listdir())  # 目录下资源名称

print(os.path.isdir('resource'))
print(os.path.isfile('复习.py'))

filename_path, extension = os.path.splitext('文件操作.py')
print(filename_path)
print(extension)
try:
    e = 1 / 0
except ZeroDivisionError as e:
    print('0为除数错')
else:
    print('没错')
finally:
    print('这一趴结束')

class ZeroZeroError(Exception):
    def __str__(self):
        return '长度不合法'
user = '123'
try:
    if 6 <= len(user):
        print('合法')
    else:
        raise ZeroZeroError()
except ZeroZeroError as e:
    print(e)
import random

print(random.uniform(0, 9999))
print(random.randint(0, 9999))

list1 = ['zhang', 'wang', 'li']
random.shuffle(list1)
print(list1)
# random.seed(2)
print(random.sample(list1, 1))

print(random.choice(['linux', 'mysql', 'shll']))

# 时间模块
import time

print(time.time())
print(time.gmtime())
print(time.localtime())
print(time.ctime())

time1 = time.localtime()
time2 = time.time()
print(time.asctime(time1))
print(time.mktime(time1))

str_time = "2022/12/19 15:45:53"
print(time1)
print(time.strftime('%Y/%m/%d %H:%M:%S', time1))
